package com.igeek.health.exception;

import com.igeek.health.result.Result;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author fengqq
 * @Description 全局异常处理器
 * @Date 2024/8/28  10:26
 *
 * 全局异常处理器：
 * 针对前后端分离：@RestControllerAdvice+@ExceptionHandler
 */
@RestControllerAdvice
public class HealthControllerAdvice {

    //针对自定义异常 HealthException 异常的处理方法
    @ExceptionHandler(HealthException.class)
    public Result resolveHealth(HealthException ex){
        return new Result(false,ex.getMessage());
    }

    //针对系统异常
    @ExceptionHandler(Exception.class)
    public Result resolveException(Exception ex){
        ex.printStackTrace();
        return new Result(false,"内部错误");
    }
    //DisabledException   用户已失效
    //InternalAuthenticationServiceException  不存在当前用户信息！
    //BadCredentialsException 用户名或密码错误
    //AccessDeniedException 不允许访问
    @ExceptionHandler(AccessDeniedException.class)
    public Result resolveException(AccessDeniedException ex){
        ex.printStackTrace();
        return new Result(false,"403权限不足");
    }
}
